<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加用户','./admin-add.html')"><i class="layui-icon"></i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：88 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>姓名</th>
            <th>合同内容</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <th>备注</th>
            <th>操作</th>
        </thead>
        <tbody>
        <tr th:each="x:${list}">
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i>
                </div>
            </td>
            <td th:text="${x.contractId}"></td>
            <td th:text="${x.employee.eName}"></td>
            <td class="td-manage">
                <a title="合同" onclick="x_admin_show('合同内容','/deployment/contract-content')" href="javascript:;">
                    <i class="layui-icon" th:text="${x.contractContent}"></i>
                </a>
            </td><!--th:text="${#dates.format(deploy.getTime(),'yyyy-MM-dd')}"x.employee.entryTime()-->
            <td th:text="${#dates.format(x.employee.entryTime,'yyyy-MM-dd')}"></td>
            <td th:text="${#dates.format(x.stopDay,'yyyy-MM-dd')}"></td>
            <td class="td-status" th:if="${x.employee.status==0}">
                <span class="layui-btn layui-btn-normal layui-btn-mini">在职</span>
            </td>
            <td class="td-status" th:if="${x.employee.status==1}">
                <span class="layui-btn layui-btn-normal layui-btn-mini">兼职</span>
            </td>
            <td class="td-status" th:if="${x.employee.status==2}">
                <span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">离职</span>
            </td>
            <td class="td-manage" style="align-content: center">
                <a title="编辑" onclick="x_admin_show('编辑','admin-edit.html')" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="del_member(this)" href="javascript:;" >
                    <i class="layui-icon">&#xe640;</i>
                </a>
                <a title="上传合同"  href="javascript:;" class="layui-upload" id="test1">
                    <i class="layui-icon">&#xe681;</i>
                </a>
                <a title="下载合同" href="javascript:;" class="layui-upload" id="test1">
                    <i class="layui-icon">&#xe601;</i>
                </a>
                <a title="邮件发送" onclick="sendMail(this)" href="javascript:;" >
                    <i class="layui-icon">&#xe655;</i>
                </a>
            </td>
        </tr>
        </tbody>
    </table>
    <div class="page">
        <div>
            <a class="prev" href="">&lt;&lt;</a>
            <a class="num" href="">1</a>
            <span class="current">2</span>
            <a class="num" href="">3</a>
            <a class="num" href="">489</a>
            <a class="next" href="">&gt;&gt;</a>
        </div>
    </div>

</div>
<script>

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    /*用户-删除*/
    function del_member(obj) {
        var contractId = $(obj).parents("tr").find("td").eq(1).text();
        console.log(contractId);

        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                url: '/contract/delContract',
                type: 'post',
                async: false,
                dataType: 'json',
                data: {'contractId': contractId},
                success: function (data) {
                    console.log("=====");
                    if (data == true) {
                        console.log("---");
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('删除失败!', {icon: 1, time: 1000});
                    }
                },
                error: function () {
                    console.log(2);
                }
            });
        });
    }

    /*用户-删除*/
    function sendMail(obj, id) {
        layer.confirm('确认要发送吗？', function (index) {
            $.ajax({
                url:'/contract/send',
                type:'post',
                dataType:'json',
                success:function (data) {
                    if (data.code == 0){
                        layer.msg('发送成功!', {icon: 1, time: 1000});
                    }else {
                        layer.msg('发送失败1!', {icon: 6, time: 1000});
                    }
                },
                error:function () {
                    layer.msg('发送失败!', {icon: 6, time: 1000});
                }
            });
        });
    }

    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }

    //上传
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            //后端地址
            ,url: '/userInfo/upload/'
            //隐藏域的地址，就在上面代码哪里
            ,accept:'url'
            ,size:50000
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    //显示上传图片
                    $('#demo1').attr('src', result);
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                var demoText = $('#demoText');
                demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                var fileupload = $(".image");
                //把图片在项目中的路径存入到 属性 class=image的input框中
                fileupload.attr("value",res.src);
                console.log(fileupload.attr("value"));
            }
            ,error: function(){
                layer.msg('上传失败', {icon: 5})
            }
        });
    });
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>